import java.util.Arrays;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        int w, h, x, y;
        int[][] arr = {
                {0, 3, 4, 10, 11, 20, 21},
                {2, 5, 9, 12, 19, 22, 29},
                {6, 8, 13, 18, 23, 28, 30},
                {7, 14, 17, 24, 27, 31, 34},
                {15, 16, 25, 26, 32, 33, 35},
        };
//        int[][] arr = {
//                {1,3,4,7},
//                {2,5,6,8}
//        };

        System.out.println(checkRight(arr, 4, 2) || checkLeft(arr, 4, 2));
    }

    public static boolean checkRight(int[][] arr, int w, int h) {
        int x = 0, y = 0, tx = 0, ty = 0;
        while (x < w - 1 || y < h - 1) {
            if (y < h - 1)
                y++;
            else
                x++;
            if (arr[y][x] <= arr[ty][tx])
                return false;
            tx = x;
            ty = y;
            while (y > 0 && x < w - 1) {
                x++;
                y--;
                if (arr[y][x] <= arr[ty][tx])
                    return false;
                tx = x;
                ty = y;
            }
            if (x < w - 1)
                x++;
            else
                y++;
            if (arr[y][x] <= arr[ty][tx])
                return false;
            while (y < h - 1 && x > 0) {
                x--;
                y++;
                if (arr[y][x] <= arr[ty][tx])
                    return false;
                tx = x;
                ty = y;
            }
        }
        return true;
    }

    public static boolean checkLeft(int[][] arr, int w, int h) {
        int x = 0, y = 0, tx = 0, ty = 0;
        while (x < w - 1 || y < h - 1) {
            if (y < h - 1)
                y++;
            else
                x++;
            if (arr[y][x] >= arr[ty][tx])
                return false;
            tx = x;
            ty = y;
            while (y > 0 && x < w - 1) {
                x++;
                y--;
                if (arr[y][x] >= arr[ty][tx])
                    return false;
                tx = x;
                ty = y;
            }
            if (x < w - 1)
                x++;
            else
                y++;
            if (arr[y][x] >= arr[ty][tx])
                return false;
            while (y < h - 1 && x > 0) {
                x--;
                y++;
                if (arr[y][x] >= arr[ty][tx])
                    return false;
                tx = x;
                ty = y;
            }
        }
        return true;
    }
}